import request from './request.js'
const accountInfo = uni.getAccountInfoSync()
const appId = accountInfo.miniProgram.appId;
import config from '@/config.js'

function regionsList() {
	return request({
		url: `/systemj/region/regionsList`,
		method: 'get'
	})
}
function countryList() {
	return request({
		url: `/systemj/country/countryList`,
		method: 'get'
	})
}
function getMyPersonInfoWithcptId(cptId) {
	return request({
		url: `/systemj/personInfo/getMyPersonInfo/${cptId}`,
		method: 'get'
	})
}
function getMyPersonInfo() {
	return request({
		url: `/systemj/personInfo/getMyPersonInfo`,
		method: 'get'
	})
}

function saveMyBaseInfo(data) {
	return request({
		url: `/systemj/personInfo/saveMyBaseInfo`,
		method: 'post',
		params: data
	})
}
// 保存补充信息
function saveSupplementInfo(data) {
	return request({
		url: `/league/competitionPersonInfo/savePersonInfo`,
		method: 'post',
		params: data
	})
}
//获取补充信息
function getSupplementInfo(id) {
	return request({
		url: `/league/competitionPersonInfo/${id}`,
		method: 'get'
	})
}
function updateAvatar(avatarUrl) {
	return request({
		url: `/system/wx/updateAvatar`,
		method: 'post',
		params: avatarUrl
	})
}
function downloadpz(cptId,groupId) {
	return request({
		url: `/pdf/getPayedOrderPdfUrl/${cptId}/${groupId||0}`,
		method: 'post'
	})
}


// 头像上传
function uploadFile(e){
	let avatarUrl = e.detail.avatarUrl
	uni.showLoading({
		title: '加载中'
	});
	return uni.uploadFile({
		url: config.baseUrl_api + '/upload/uploadImg',
		filePath: avatarUrl,
		name: 'image',
		// success: uploadFileRes => {
		// 	// 注意：这里返回的uploadFileRes.data 为JSON 需要自己去转换
		// 	let data = JSON.parse(uploadFileRes.data);
		// 	return data
		// },
		// fail: error => {
		// 	console.log(error)
		// },
		// complete: () => {
		// 	uni.hideLoading();
		// }
	}).then(res=>{
			let data = JSON.parse(res.data);
			return data
	}).finally(()=>{
		uni.hideLoading();
	});
}
// 图片上传
function uploadImg(e){
	const tempFilePaths = e.tempFilePaths;
	const imgUrl=tempFilePaths[0]
	uni.showLoading({
		title: '加载中'
	});
	return uni.uploadFile({
		url: config.baseUrl_api + '/upload/uploadImg',
		filePath: imgUrl,
		name: 'image'
	}).then(res=>{
			let data = JSON.parse(res.data);
			return data
	}).finally(()=>{
		uni.hideLoading();
	});
}
// 图片上传
function uploadImgHasCrop(e){
	const tempFilePaths = e.tempFilePaths;
	const imgUrl=tempFilePaths[0]
	wx.cropImage({
		src: imgUrl,
		cropScale: '4:3',
		success: function(resp){
			uni.showLoading({
				title: '加载中'
			});
			uni.uploadFile({
				url: config.baseUrl_api + '/upload/uploadImg',
				filePath: resp.tempFilePath,
				name: 'image'
			}).then(res => {
					let data = JSON.parse(res.data);
					return data
			}).finally(()=>{
				uni.hideLoading();
			});
			
		}
	})
	
	

}
// 文件上传
function uploadFile2(e){
	const fileUrl=e.tempFilePaths[0]
	uni.showLoading({
		title: '加载中'
	});
	return uni.uploadFile({
		url: config.baseUrl_api + '/upload/upLoadToFileServer',
		filePath: fileUrl,
		name: 'file'
	}).then(res=>{
			let data = JSON.parse(res.data);
			return data
	}).finally(()=>{
		uni.hideLoading();
	});
}

// 获取我创建的团队列表
function getMyGroupList() {
	return request({
		url: `/league/group/getMyGroupList`,
		method: 'get'
	})
}
function deleteMyGroup(groupId) {
	return request({
		url: `/league/group/deleteMyGroup/${groupId}`,
		method: 'post'
	})
}
// 根据Id获取我的团队
function getGroupById(groupId) {
	return request({
		url: `/league/group/getMyGroup/${groupId}`,
		method: 'get'
	})
}
function getMyGroupForCpt(groupId,cptId) {
	return request({
		url: `/league/group/getMyGroupForCpt/${groupId}/${cptId}`,
		method: 'get'
	})
}
// 根据Id获取人员信息
function getPersonInfoById(id) {
	return request({
		url: `/systemj/personInfo/${id}`,
		method: 'get',
		params: id
	})
}
// 新建团队
function saveMyGroup(data) {
	return request({
		url: `/league/group/saveMyGroup`,
		method: 'post',
		params: data
	})
}
// 退出团队
function leaveGroup(groupId) {
	return request({
		url: `/systemj/personInfo/leaveGroup/${groupId}`,
		method: 'post',
		params: groupId
	})
}

// 人员修改
function editPersonInfo(params) {
	return request({
		url: `/systemj/personInfo`,
		method: 'put',
		params: params
	})
}
// 人员删除
function delPerson(id) {
	return request({
		url: `/systemj/personInfo/${id}`,
		method: 'delete',
		params: id
	})
}


function savePersonForMyPerson(data) {
	return request({
		url: `/systemj/personInfo/savePersonForMyPerson`,
		method: 'post',
		params: data
	})
}
function savePersonForMyGroup(data) {
	return request({
		url: `/systemj/personInfo/savePersonForMyGroup`,
		method: 'post',
		params: data
	})
}
function saveMyTeam(data) {
	return request({
		url: `/league/team/saveMyTeam`,
		method: 'post',
		params: data
	})
}
function checkPerson(data) {
	return request({
		url: `/systemj/personInfo/checkPersonInfoExist`,
		method: 'post',
		params: data
	})
}
// 获取团队下的队伍
function getMyTeamList(cptId,groupId) {
	return request({
		url: `/league/team/getTeamList/${cptId}/${groupId}`,
		method: 'get'
	})
}
function delRank(id) {
	return request({
		url: `/league/team/${id}`,
		method: 'delete',
		params: id
	})
}
//获取赛事列表
function getMaList(params) {
	return request({
		url: `/league/competition/maList`,
		method: 'get',
		params: params
	})
}
function getMatchById(params) {
	return request({
		url: `/league/competition/detail`,
		method: 'get',
		params: params
	})
}

function getMySignInfo(data) {
	return request({
		url: `/league/sign/getMySignInfo`,
		method: 'post',
		params: data
	})
}
function getMySignInfoList(data) {
	return request({
		url: `/league/sign/getMySignInfoList`,
		method: 'post',
		params: data
	})
}
function getCanSignProjectList(cptId) {
	return request({
		url: `/league/competitionProject/getCanSignProjectListFromSelectPerson/${cptId}`,
		method: 'get'
	})
}
function getCanSignGroupListFromSelectPerson(projectId,personId) {
	return request({
		url: `/league/competitionGroup/getCanSignGroupListFromSelectPerson/${projectId}/${personId}`,
		method: 'get'
	})
}
function getCanSignlevelListFromSelectPerson(groupId,personId) {
	return request({
		url: `/league/competitionLevel/getCanSignLevelListFromSelectPerson/${groupId}/${personId}`,
		method: 'get'
	})
}
// 获取赛事下的已报团队
function getGroupListByCptId(cptId) {
	return request({
		url: `/league/group/getGroupListByCptId/${cptId}`,
		method: 'get'
	})
}
function singleSignSavePerson(data) {
	return request({
		url: `/league/unitCompetitionRole/savePersonInfo`,
		method: 'post',
		params: data
	})
}
function groupSignSavePerson(data) {
	return request({
		url: `/league/unitCompetitionRole/saveGroupInfo`,
		method: 'post',
		params: data
	})
}
function sportsmanDone(data) {
	return request({
		url: `/league/sign/signUp`,
		method: 'post',
		params: data
	})
}
function getMyOrderList(params) {
	return request({
		url: `/league/signOrder/getMyOrderList`,
		method: 'get',
		params: params
	})
}
function getMyMatchs(params) {
	return request({
		url: `/league/sign/getMySignPage`,
		method: 'get',
		params: params
	})
}
function getMyOrderDetail(orderId) {
	return request({
		url: `/league/signOrder/getMyOrderDetail/${orderId}`,
		method: 'get'
	})
}
function getGroupListByProjectId(cptProjectId) {
	return request({
		url: `/league/competitionGroup/getGroupListByProjectId/${cptProjectId}`,
		method: 'get'
	})
}
function getLeveListByGroupId(cptGroupId) {
	return request({
		url: `/league/competitionLevel/getLeveListByGroupId/${cptGroupId}`,
		method: 'get'
	})
}



function getCanSignLevelPerson(data) {
	return request({
		url: `/league/competitionLevel/getCanSignLevelPerson`,
		method: 'post',
		params: data
	})
}


// 获取团队报名时已选人员
function getChooseDoneGroupCoachs(cptId,groupId) {
	return request({
		url: `/league/unitCompetitionRole/getGroupInfo/${cptId}/${groupId}`,
		method: 'get'
	})
}
// 获取个人报名时已选人员
function getChooseDoneSingleCoachs(cptId) {
	return request({
		url: `/league/unitCompetitionRole/getPersonInfo/${cptId}`,
		method: 'get'
	})
}
// 删除报名接口
function deleteSign(id) {
	return request({
		url: `/league/sign/deleteSign/${id}`,
		method: 'post'
	})
}
// 修改
function modSignUp(data) {
	return request({
		url: `/league/sign/modSignUp/${data.id}`,
		method: 'post',
		params: data
	})
}


function getTotalFee(data) {
	return request({
		url: `/league/expenseConfig/getTotalFee`,
		method: 'post',
		params: data
	})
}
// 生成订单
function commitSign(data) {
	return request({
		url: `/league/sign/commitSign`,
		method: 'post',
		params: data
	})
}
// 支付 orderId,payType
function payMatch(data) {
	return request({
		url: `/league/signOrder/payForOrder`,
		method: 'post',
		params: data
	})
}
function maPayConfirm(params) {
	return request({
		url: `/league/signOrder/maPayConfirm`,
		method: 'post',
		params: params
	})
}
function cancelMyUnPayedOrder(orderId) {
	return request({
		url: `/league/signOrder/cancelMyUnPayedOrder/${orderId}`,
		method: 'post'
	})
}
function getMySignCptList(query) {
	return request({
		url: `/league/competition/getMySignCptList`,
		method: 'get',
		params: query
	})
}
function getMySignDetailById(params) {
	return request({
		url: `/league/sign/getMySignPage`,
		method: 'get',
		params: params
	})
}
function getMySignListFromOrderList(orderId) {
	return request({
		url: `/league/sign/getMySignListFromOrderList/${orderId}`,
		method: 'get'
	})
}
function getMySignListFromBaoXiang(data) {
	return request({
		url: `/league/sign/getMySignListFromBaoXiang`,
		method: 'post',
		params: data
	})
}
function recoverMySign(data) {
	return request({
		url: `/league/sign/recoverMySign`,
		method: 'post',
		params: data
	})
}
function getBaseProject() {
	return request({
		url: `/systemj/baseProject/list`,
		method: 'get'
	})
}
function getMySignListTree(cptId,personId,teamId) {
	return request({
		url: `/league/competitionProject/getAllInfoFromSelectPerson/${cptId}/${personId}/${teamId||0}`,
		method: 'get'
	})
}
function getMySignIds(cptId,personId,teamId) {
	return request({
		url: `/league/sign/getSignEntityByPersonId/${cptId}/${personId}/${teamId||0}`,
		method: 'get'
	})
}
function querySonLevel(parentId) {
	return request({
		url: `/league/competitionSonLevel/querySonLevelByParentId/${parentId}`,
		method: 'get'
	})
}
function saveMyGroupExtraInfo(data) {
  return request({
    url: `/league/competitionGroupInfo/saveMyGroupExtraInfo`,
    method: 'post',
    params: data
  })
}
export {updateAvatar,
	regionsList,countryList,getMyPersonInfo,getMyPersonInfoWithcptId,saveMyBaseInfo,
	uploadFile,uploadImg,uploadFile2,getMyGroupList,saveMyGroup,getGroupById,leaveGroup,getPersonInfoById,
	checkPerson,
	editPersonInfo,delPerson,savePersonForMyPerson,savePersonForMyGroup,saveMyTeam,getMyTeamList,delRank,
	getMaList,getMatchById,getMySignInfo,getCanSignProjectList,getCanSignGroupListFromSelectPerson,getGroupListByCptId,
	saveSupplementInfo,singleSignSavePerson,sportsmanDone,getMyOrderList,getGroupListByProjectId,getLeveListByGroupId,
	getMyOrderDetail,commitSign,groupSignSavePerson,getChooseDoneGroupCoachs,getChooseDoneSingleCoachs,
	getCanSignlevelListFromSelectPerson,deleteSign,getMyMatchs,getCanSignLevelPerson,
	getTotalFee,payMatch,
	getMySignCptList,getMySignDetailById,
	getMySignListFromOrderList,cancelMyUnPayedOrder,
	getSupplementInfo,deleteMyGroup,recoverMySign,getMySignListFromBaoXiang,
	getBaseProject,getMyGroupForCpt,
	getMySignInfoList,modSignUp,
	getMySignListTree,getMySignIds,querySonLevel,maPayConfirm,
	saveMyGroupExtraInfo,
	uploadImgHasCrop,downloadpz
}
